home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / gnu_tile_forth.lha / tst / calc.bnf < prev    next >
Text File  |  1992-05-19  |  2KB  |  101 lines

  1. \
  2. \  INFIX CALCULATOR GRAMMAR DEFINITIONS
  3. \
  4. \  Copyright (C) 1990 by Mikael R.K. Patel
  5. \
  6. \  Computer Aided Design Laboratory (CADLAB)
  7. \  Department of Computer and Information Science
  8. \  Linkoping University
  9. \  S-581 83 LINKOPING
  10. \  SWEDEN
  11. \
  12. \  Email: mip@ida.liu.se
  13. \
  14. \  Started on: 21 February 1990
  15. \
  16. \  Last updated on: 22 February 1990
  17. \
  18. \  Dependencies:
  19. \       (forth) forth, parser, bnf
  20. \
  21. \  Description:
  22. \       Infix notation grammar definitions and semantic binding.
  23. \       Translates infix notation to postfix (forth).
  24. \    Grammar defined using Extended Backus-Naur Form package.
  25. \
  26. \  Copying:
  27. \       This program is free software; you can redistribute it and\or modify
  28. \       it under the terms of the GNU General Public License as published by
  29. \       the Free Software Foundation; either version 1, or (at your option)
  30. \       any later version.
  31. \
  32. \       This program is distributed in the hope that it will be useful,
  33. \       but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. \       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. \       GNU General Public License for more details.
  36. \
  37. \       You should have received a copy of the GNU General Public License
  38. \       along with this program; see the file COPYING.  If not, write to
  39. \       the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  40.  
  41. .( Loading Backus-Naur Form Infix Calculator definitions...) cr
  42.  
  43. #include parser.f83
  44. #include bnf.f83
  45.  
  46. parser forth definitions
  47.  
  48. \ Exported calculator grammar symbol
  49.  
  50. vocabulary calculator
  51.  
  52. symbol calc
  53.  
  54. parser calculator definitions
  55.  
  56. \ Internal semantic actions
  57.  
  58. : .number ( x -- )
  59.   .                     ( Semantic action to show binding)
  60. ;
  61.  
  62. \ Internal grammar symbols
  63.  
  64. symbol expr
  65. symbol $
  66. symbol term
  67. symbol expr0
  68. symbol expr1
  69. symbol -
  70. symbol +
  71. symbol fact
  72. symbol term0
  73. symbol *
  74. symbol /
  75. symbol mod
  76. symbol (
  77. symbol )
  78.  
  79. \ Factorized and left-to-right execution grammar for expressions
  80.  
  81. bnf interact
  82.  
  83. <calc> ::= <expr> <eoln> @ calculator: .number    
  84. <expr> ::= <term> <expr0>
  85. <expr0> ::= <expr1> <expr0>
  86.          |  <empty> 
  87. <expr1> ::= - <term> @ forth: -
  88.       |  + <term> @ forth: + 
  89. <term> ::= <fact> <term0> 
  90. <term0> ::= * <term> @ forth: * 
  91.      |  / <term> @ forth: / 
  92.          |  mod <term> @ forth: mod 
  93.      |  <empty> 
  94. <fact> ::= ( <expr> ) 
  95.         |  - <fact> @ forth: negate 
  96.     |  <number> 
  97.  
  98. forth
  99.  
  100. forth only
  101.